﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SystemConfig.aspx.cs" Inherits="Web.Admin.Page_System.SystemConfig" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>

<!DOCTYPE html>

<%="<!--[if IE 8]> <html class=\"ie8 no-js\"> <![endif]-->"%>
<%="<!--[if IE 9]> <html class=\"ie9 no-js\"> <![endif]-->"%>
<%="<!--[if !IE]><!-->"%>
<html>
<%="<!--<![endif]-->"%>
    <!-- BEGIN HEAD -->

    <head>
        <meta charset="utf-8" />
        <title><%=Evan.Common.CommFun.GetAppSetting("AdminTitle") %> - 后台管理系统</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta content="width=device-width, initial-scale=1" name="viewport" />
        <!-- #include file="../include/com_res_css.inc" -->
    </head>
    <!-- END HEAD -->

    <body class="page-header-fixed page-sidebar-closed-hide-logo page-content-white">
        <!-- BEGIN HEADER -->
        
        <!-- #include file="../include/top_bar.inc" -->

        <!-- END HEADER -->
        <!-- BEGIN HEADER & CONTENT DIVIDER -->
        <div class="clearfix"> </div>
        <!-- END HEADER & CONTENT DIVIDER -->
        <!-- BEGIN CONTAINER -->
        <div class="page-container">
            <!-- BEGIN SIDEBAR -->
            
            <!-- #include file="../include/left_menu.inc" -->
            
            <!-- END SIDEBAR -->
            <!-- BEGIN CONTENT -->
            <div class="page-content-wrapper">
                <!-- BEGIN CONTENT BODY -->
                <div class="page-content">
                    <!-- BEGIN PAGE HEADER-->
                    <!-- BEGIN THEME PANEL -->
                    <!-- #include file="../include/theme_panel.inc" -->
                    <h3 class="page-title"> 系统配置管理 </h3>
                    <!-- END PAGE TITLE-->
                    <!-- END PAGE HEADER-->
                    <!-- BEGIN PAGE CONTENT-->
                    <% List<category> cateList = GetCategoryList(); %>
                    <% List<item> itemList = new List<item>(); %>
                                    <div class="portlet light bordered">
                                        <div class="portlet-title tabbable-line">

                                            <ul class="nav nav-tabs ">
                                                <% for (int i = 0; i < cateList.Count; i++) { %>
                                                <li class="<%= i==0?"active":"" %> <%= cateList[i].show==0?"hide":"" %>">
                                                    <a href="#tab_<%=i %>" data-toggle="tab" aria-expanded="true"> <%=cateList[i].name %> </a>
                                                </li>        
                                                <% } %>
                                                
                                            </ul>
                                        
                                            <div class="caption">
                                                <i class="glyphicon glyphicon-cog font-red"></i>
                                                <span class="caption-subject font-red bold uppercase">系统配置管理</span> 
                                            </div>

                                        </div>

                                        <div class="tab-content">

                                            <% for (int i = 0; i < cateList.Count; i++) { %>

                                            <div class="tab-pane <%= i==0?"active":"" %>" id="tab_<%=i %>">
                                                <div class="form">
                                                    <div class="form-horizontal form-row-seperated">
                                                        <div class="form-body">
                                                            <% itemList = GetItemListByCategory(cateList[i].name); %>
                                                            <% foreach (var item in itemList) {
                                                                   Response.Write(Evan.Common.HtmlHelper.HtmlBuild(new Evan.Model.SysModel.HtmlHelperModel { Title = item.title, PlaceHoder = item.notice, Notice = item.notice, FieldName = item.name, FieldVerify = "", MaxLength = 5000, DefaultValue = item.value, Hide = (item.show == 0), FieldType = "input" }));
                                                            } %>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>

                                            <% } %>

                                        </div>

                                        <div class="form-actions form-submit-row">
                                            <div class="form-group">
                                                <label class="control-label col-md-2"></label>
                                                <div class="col-md-6">
                                                    <button type="button" data-loading-text="保存中..." class="btn green saveSysConfig" ><i class="fa fa-check"></i> 保存配置 </button>
                                                    &nbsp;&nbsp;<span style="color:gray;">保存配置后需要重启网站才能生效哦</span>
                                                </div>
                                            </div>  
                                            <div class="clear"></div>
                                        </div>

                                    </div>

                    
                    <!-- END PAGE CONTENT-->
                </div>
                <!-- END CONTENT BODY -->
            </div>
            <!-- END CONTENT -->
            
        </div>
        <!-- END CONTAINER -->
        <!-- #include file="../include/footer.inc" -->
        <!-- #include file="../include/com_res_js.inc" -->
        <script type="text/javascript">
            $(function () {

                function MakeConfigData() {
                    var models = {};
                    $("[field]").each(function (i, e) {
                        var value = GetConfigData(e);
                        models[$(e).attr("field")] = (value == null ? "" : value);
                    });
                    return models;
                }
                function GetConfigData(e) {
                    var type = $(e).attr("field_type").toUpperCase();
                    var values = "";
                    switch (type) {
                        case "INPUT":
                            values = $(e).val();
                            break;
                        default:
                            values = "";
                            break;
                    }
                    values = StrEnCode(values);
                    return (values);
                }
                

                $(".saveSysConfig").on("click", function () {
                    //拿到整个文档的内容
                    var _this = this;
                    model = MakeConfigData();
                    var data = { model: JSON.stringify(model) };
                    $(_this).button('loading');
                    AjaxSubmit(appConfig.adminPath + "ashx/ajax.ashx", "savesiteconfig", data, function (f, d) {
                        $(_this).button('reset');
                        //console.log(f, d);
                        if (f) {
                            //请求成功
                            if (parseInt(d.result) == 1) {
                                alert("保存成功", function () {
                                    setTimeout(function () {
                                        window.location.href = window.location.href;
                                    }, 500);
                                });
                            }
                            else if (parseInt(d.result) == -99) {
                                alert("未登录或者登录超时");
                            }
                            else if (parseInt(d.result) == -100) {
                                alert("权限不足");
                            }
                            else if (parseInt(d.result) == -1) {

                            }
                            else {

                            }
                        } else {
                            //请求失败
                            alert("保存失败 , 请稍后重试");
                        }
                    });
                });
            })
        </script>
    </body>
  
</html>
